using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;

public abstract class DynamicProp : ScriptableObject
{
    [LabelText("节点名称")] public string nodeName;

    [LabelText("节点中文名")] public string ZHName;

    /// <summary>
    /// 节点名称
    /// </summary>
    public string Name
    {
        get => nodeName;
        set => nodeName = value;
    }

    /// <summary>
    /// 节点颜色
    /// </summary>
    [LabelText("节点颜色")] public Color NodeColor = Color.white;

    /// <summary>
    /// 是否含有重名属性
    /// </summary>
    private bool hasSameName;

    [InfoBox("重复属性名称", InfoMessageType.Error, "hasSameName")]

    public List<NodeProperty> props = new List<NodeProperty>();

    public virtual void Generate(){}
    
    /// <summary>
    /// 检查是否有同名对象
    /// </summary>
    /// <returns></returns>
    protected bool checkSameName()
    {
        hasSameName = false;
        // Check same name
        for (int i = 0; i < props.Count; i++)
        {
            var p1 = props[i];
            for (int j = i + 1; j < props.Count; j++)
            {
                var p2 = props[j];
                if (p1.PropName.Equals(p2.PropName))
                {
                    hasSameName = true;
                    return hasSameName;
                }
            }
            // node class name == prop name
            if (nodeName.Equals(p1.Type.ToString()))
            {
                Debug.LogError("[DynamicNode] 属性名称与 Class 名称冲突");
                hasSameName = true;
                return hasSameName;
            }
        }

        return hasSameName;
    }
}
